package com.fengxing.ams.web.facade.mouble.sys;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface ISysCodeDAO extends PagingAndSortingRepository<SysCodeVO, String>, JpaSpecificationExecutor<SysCodeVO>  {

	@Query(value = "SELECT distinct(channel) FROM zyt_sys_code", nativeQuery=true)
	List<String> getChannels();

	@Query(value = "SELECT * FROM zyt_sys_code where id=:code for update", nativeQuery=true)
	SysCodeVO getCodeForUpdate(@Param("code")String id);

	@Query(value = "SELECT t FROM SysCodeVO t where t.channel=:channel and t.role=:role and t.status=:status and t.createdEmail=:createdEmail")
	List<SysCodeVO> queryCodeByQueryVO(@Param("channel")String q_channel, @Param("role")Integer q_role,
			@Param("status")Integer q_status, @Param("createdEmail")String created_email);

	@Query(value = "SELECT * FROM zyt_sys_code where channel=:channel and status=0 order by created_date limit 0,1 for update", nativeQuery=true)
	SysCodeVO getOneCodeForUpdate(@Param("channel")String channel);
	
}

